# blib/plugs/start.py
#
#

""" start various bots. """

## blib imports

from blib import cmnds, fleet, O

## basic imports

import _thread

## default config 

config = O()
config.server = "irc.xs4all.nl"
config.port = 6667
config.nick = "botjuh"
config.username = "berenddeman"

## z config 

zconfig = O()
zconfig.server = "localhost"
zconfig.port = 6667
zconfig.nick = "botjuh"
zconfig.username = "berenddeman"
zconfig.channel = "#test"

## start command

def start(event):
    if not event.args: event.reply("start what?") ; return
    type = event.args[0]
    if type == "z":
        from blib.drivers.irc import IRCBot
        bot = IRCBot(**zconfig)
    elif type == "irc":
        from blib.drivers.irc import IRCBot
        bot = IRCBot(**config)
    elif type == "xmpp":
        from blib.drivers.xmpp import XMPPBot
        config.user = config.user or "feedbackflow@gmail.com"
        config.server = config.server or "talk.google.com"   
        config.port = 5222
        bot = XMPPBot(**config)
    elif type == "local":
        from blib.drivers.xmpp import XMPPBot
        config.user = config.user or  "test@localhost"
        config.server = config.server or "localhost"  
        config.port = 5222
        bot = XMPPBot(**config)
    else: event.reply("no %s type bot available.") ; return
    fleet.register(type, bot)
    try: _thread.start_new_thread(bot.run_forever, ())
    except: error()
    fleet.bots.append(bot)

cmnds.register("start", start)
